<template>
    <div class="app">
        <h1>vuex案例</h1>
        <div>总资产：{{ $store.state.money }}</div>
        <div>总资产：{{ money }}</div>
        <div>车车：{{ car }}</div>
        <div>数量：{{ num }}</div>
        <Man class="man"></Man>
        <Women class="women"></Women>
        <Three class="three"></Three>
    </div>
</template>

<script>
import {mapState} from 'vuex'
import Man from './components/Man'
import Women from './components/Women'
import Three from './components/Three'
export default {
    data(){
        return{
            n1:1,
            n2:2
        }
    },
    components: {
        Man,
        Women,
        Three,
    },
    created(){
        console.log(this.$store.state);
    },
    computed:mapState(['money','car']),
    computed:{
        num(){
            return this.n1 + this.n2
        },
        ...mapState(['money','car'])
    }
    // computed:{
    //     money(){
    //         return this.$store.state.money
    //     }
    // }
}
</script>

<style lang="less">
* {
    margin: 0;
    padding: 0;
    list-style: none;
    box-sizing: border-box;
}
.app {
    text-align: center;
    width: 600px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: pink;
    .man,
    .women,
    .three {
        height: 200px;
        border-bottom: 3px solid #ccc;
        background-color: #ddd;
    }
    div {
        min-height: 30px;
    }
}
</style>
